package edu.gatech.gro.model;

import edu.gatech.gro.utils.Utils;

public class Item extends AbstractObject {

	/* Attributes matching exactly the database model. */
	private int itemTypeId;
	private int groceryStoreId;
	private String name;
	private String nameClean;
	private String barCode;
	private String barCodeHash;
	private double price;
	private int currency;

	/* Attributes to ease the use of the class */
	private Item item;
	private GroceryStore groceryStore;

	public Item() {
		super();
	}

	public Item getItem() {
		// TODO: need to be improved! Not working!
		return item;
	}

	public void setItem(Item item) {
		// TODO: need to be improved! Not working!
		this.item = item;
	}

	public GroceryStore getGroceryStore() {
		// TODO: need to be improved! Not working!
		return groceryStore;
	}

	public void setGroceryStore(GroceryStore groceryStore) {
		// TODO: need to be improved! Not working!
		this.groceryStore = groceryStore;
	}

	public int getItemTypeId() {
		return itemTypeId;
	}

	public void setItemTypeId(int itemTypeId) {
		this.itemTypeId = itemTypeId;
	}

	public int getGroceryStoreId() {
		return groceryStoreId;
	}

	public void setGroceryStoreId(int groceryStoreId) {
		this.groceryStoreId = groceryStoreId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
		this.setNameClean(Utils.cleanName(name));
	}

	public String getNameClean() {
		return nameClean;
	}

	public void setNameClean(String nameClean) {
		this.nameClean = nameClean;
	}

	public String getBarCode() {
		return barCode;
	}

	public void setBarCode(String barCode) {
		this.barCode = barCode;
		this.setBarCodeHash(Utils.hash(barCode));
	}

	public String getBarCodeHash() {
		return barCodeHash;
	}

	public void setBarCodeHash(String barCodeHash) {
		this.barCodeHash = barCodeHash;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getCurrency() {
		return currency;
	}

	public void setCurrency(int currency) {
		this.currency = currency;
	}

	@Override
	public String toString() {
		StringBuilder b = new StringBuilder();
		b.append(id).append(" ");
		b.append(name).append(" ");
		return b.toString();
	}
}
